package Demo01;

public class Main {
}

class Solution {
    public static void main(String[] args) {
        System.out.println(minWindow("ab", "a"));
    }

    public static String minWindow(String s, String t) {
        if (s.length() < t.length()) {
            return "";
        }
        int[] dp = new int[256];
        int debt = t.length();
        for (char c : t.toCharArray()) {
            dp[c]--;
        }
        int l = 0;
        int start = 0;
        int len = Integer.MAX_VALUE;
        for (int r = 0; r < s.length(); r++) {
            if (dp[s.charAt(r)]++ < 0) {
                debt--;
            }
            if (debt == 0) {
                while (dp[s.charAt(l)] > 0) {
                    dp[s.charAt(l++)]--;
                }
                if (r - l + 1 < len) {
                    len = r - l + 1;
                    start = l;
                }
            }

        }
        return len == Integer.MAX_VALUE ? "" : s.substring(start, start + len);
    }
}
